#region Using Directives

using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using System.ComponentModel;

#endregion

namespace Web
{
    public abstract class StateManagedItem : IStateManagedItem
    {
        #region Fields

        private bool trackingViewState = false;
        private StateBag viewState;

        #endregion

        #region Constructor

        public StateManagedItem()
        {
            viewState = new StateBag();
        }

        #endregion

        #region Properties

        protected StateBag ViewState
        {
            get { return this.viewState; }
        }

        #endregion

        #region IStateManager Members

        [Browsable(false)]
        public bool IsTrackingViewState
        {
            get { return trackingViewState; }
        }

        public void LoadViewState(object state)
        {
            ((IStateManager)this.ViewState).LoadViewState(state);
        }

        public object SaveViewState()
        {
            return ((IStateManager)this.ViewState).SaveViewState();
        }

        public void TrackViewState()
        {
            this.trackingViewState = true;
            ((IStateManager)this.ViewState).TrackViewState();
        }

        #endregion

        #region IStateManager Members

        [Browsable(false)]
        bool IStateManager.IsTrackingViewState
        {
            get { return this.IsTrackingViewState; }
        }

        void IStateManager.LoadViewState(object state)
        {
            this.LoadViewState(state);
        }

        object IStateManager.SaveViewState()
        {
            return this.SaveViewState();
        }

        void IStateManager.TrackViewState()
        {
            this.TrackViewState();
        }

        #endregion

        #region Methods

        public void SetDirty()
        {
            viewState.SetDirty(true);
        }

        #endregion
    }
}